/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ebe.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Cleiviane
 */
public class DB {

    private Connection conn;

    public DB() throws SQLException {
        conn = pegaConexao();
    }

    synchronized static private Connection pegaConexao() throws SQLException {
        try {
            Class.forName("org.h2.Driver");
        } catch (ClassNotFoundException ex) {
            throw new SQLException("Banco de dados H2 nao está instalado");
        }
        Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/ebe", "sa", "");
        return conn;
    }

    public void close(){
        try {
            conn.close();
        } catch (SQLException ex) {
        }
    }
    
    public PreparedStatement sql(String sql) throws SQLException {
        return conn.prepareStatement(sql);
    }
}
